package org.arch_learn.spring_cloud.scn_homework.service_email_8082.service.impl;

import org.arch_learn.spring_cloud.scn_homework.service_common_dependency.request.SendEmailRequest;
import org.arch_learn.spring_cloud.scn_homework.service_email_8082.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService implements IEmailService {
    @Value("${spring.mail.username}")
    private String mailSenderAccount;
    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public void sendEmail(SendEmailRequest sendEmailRequest) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(mailSenderAccount);
        simpleMailMessage.setText(sendEmailRequest.getContent());
        simpleMailMessage.setSubject(sendEmailRequest.getSubject());
        simpleMailMessage.setTo(sendEmailRequest.getDestination());
        javaMailSender.send(simpleMailMessage);
    }
}
